package com.ruoyi.ly.controller;



import com.ruoyi.ly.domain.Project;
import com.ruoyi.ly.domain.SpaceBan;
import com.ruoyi.ly.domain.dto.PageWorkSpaceDTO;
import com.ruoyi.ly.domain.dto.WorkSpaceAddDTO;
import com.ruoyi.ly.domain.dto.WorkSpaceUpdateDTO;
import com.ruoyi.ly.domain.vo.WorkSpaceAddBanVO;
import com.ruoyi.ly.domain.vo.WorkSpaceAddFloorVO;
import com.ruoyi.ly.domain.vo.WorkSpaceDetailVO;
import com.ruoyi.ly.service.WorkSpaceService;
import com.ruoyi.ly.utils.PageResult;
import com.ruoyi.ly.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/workSpace")
@Slf4j
@Api("工作区管理接口")
public class WorkSpaceController {


    @Autowired
    private WorkSpaceService workSpaceService;

    //分页查询
    @ApiOperation("分页查询工作区")
    @GetMapping("/page")
    public Result<PageResult> page(PageWorkSpaceDTO pageWorkSpaceDTO) {
        log.info("分页查询：{}", pageWorkSpaceDTO);
        PageResult pageResult = workSpaceService.pageQuery(pageWorkSpaceDTO);
        return Result.success(pageResult);
    }

    //工作区删除
    @ApiOperation("删除工作区")
    @DeleteMapping("/delete/{siteGroupId}")
    public Result delete(@PathVariable("siteGroupId") Long siteGroupId) {
        log.info("工作区删除：{}", siteGroupId);
        workSpaceService.delete(siteGroupId);
        return Result.success();
    }

    //创建工作区
    @ApiOperation("创建工作区")
    @PostMapping("/add")
    public Result insert(@RequestBody WorkSpaceAddDTO workSpaceAddDTO) {
        log.info("创建工作区：{}",workSpaceAddDTO);
        workSpaceService.insert(workSpaceAddDTO);
        return Result.success();
    }

    //根据工作区siteGroupId查询工作区
    @ApiOperation("根据工作区siteGroupId查询工作区")
    @GetMapping("/selectById")
    public Result<WorkSpaceDetailVO> selectById(Long siteGroupId) {
        log.info("根据siteGroupId查询工作区：{}",siteGroupId);
        WorkSpaceDetailVO workSpaceDetailVO = workSpaceService.selectById(siteGroupId);
        return Result.success(workSpaceDetailVO);
    }

    //修改工作区信息
    @ApiOperation("修改工作区信息")
    @PutMapping("/update")
    public Result update(@RequestBody WorkSpaceUpdateDTO workSpaceUpdateDTO) {
        log.info("修改工作区信息：{}",workSpaceUpdateDTO);
        workSpaceService.update(workSpaceUpdateDTO);
        return Result.success();
    }

    //根据项目id查询所属楼栋
    @ApiOperation("根据项目id查询所属楼栋")
    @GetMapping("/selectByProjectId")
    public Result<List<WorkSpaceAddBanVO>> selectByProjectId(Long projectId) {
        log.info("根据项目id查询所属楼栋",projectId);
        List<WorkSpaceAddBanVO> workSpaceAddBanVO = workSpaceService.selectByProjectId(projectId);
        return Result.success(workSpaceAddBanVO);
    }

    //根据项目id和楼栋id查询所属楼层
    @ApiOperation("根据项目id和楼栋id查询所属楼层")
    @GetMapping("/selectByProjectAndBanId")
    public Result<List<WorkSpaceAddFloorVO>> selectByProjectId(@Param("projectId") Long projectId,@Param("banId") Long banId){
        log.info("根据项目id和楼栋id查询所属楼层",projectId,banId);
        List<WorkSpaceAddFloorVO> workSpaceAddFloorVO = workSpaceService.selectByProjectAndBanId(projectId,banId);
        return Result.success(workSpaceAddFloorVO);
    }

    //查询所有的楼栋
    @ApiOperation("查询所有的楼栋名称")
    @GetMapping("/selectAllBan")
    public Result<List<SpaceBan>> selectAllBan(){
        log.info("查询所有的楼栋");
        List<SpaceBan> spaceBanList = workSpaceService.selectAllBan();
        return Result.success(spaceBanList);
    }

    //查询所有的项目
    @ApiOperation("查询所有的项目名称")
    @GetMapping("/selectAllProject")
    public Result<List<Project>> selectAllProject(){
        log.info("查询所有的项目");
        List<Project> projectList = workSpaceService.selectAllProject();
        return Result.success(projectList);
    }

}
